<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>待审核语料库</title>
	<link rel="stylesheet" href="../../component/pear/css/pear.css" />
</head>
<body class="pear-container">
	<div class="layui-card">
		<div class="layui-card-body">
			<form class="layui-form" action="">
				<div class="layui-form-item">
					<div class="layui-form-item layui-inline">
						<label class="layui-form-label">词义</label>
						<div class="layui-input-inline">
							<input type="text" name="word" placeholder="请输入查询词义" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item layui-inline">
						<label class="layui-form-label">作者</label>
						<div class="layui-input-inline">
							<input type="text" name="author" placeholder="请输入查询作者" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item layui-inline">
						<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
							<i class="layui-icon layui-icon-search"></i>
							查询
						</button>
						<button type="reset" class="pear-btn pear-btn-md">
							<i class="layui-icon layui-icon-refresh"></i>
							重置
						</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	<div class="layui-card">
		<div class="layui-card-body">
			<table id="user-table" lay-filter="user-table"></table>
		</div>
	</div>

	<script type="text/html" id="user-toolbar">
		<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="checkok">
			<i class="layui-icon layui-icon-ok"></i>
			批量审核通过
		</button>
		<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="checknook">
			<i class="layui-icon layui-icon-close"></i>
			批量审核不通过
		</button>
	</script>

	<script type="text/html" id="user-bar">
		<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="view">
		<i class="layui-icon layui-icon-chart-screen"></i>查看
		</button>
	</script>

	<script type="text/html" id="user-createTime">
		{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd')}}
	</script>

	<script src="../../component/layui/layui.js"></script>
	<script src="../../component/pear/pear.js"></script>
	<script>
        layui.use(['layer', 'form', 'table', 'jquery', 'common', 'http', 'toast','loading'], function () {
			let layer = layui.layer;	
            let form = layui.form;
			let table = layui.table;		
			let $ = layui.jquery;
			let common = layui.common;
			let http = layui.http;
			let toast = layui.toast;
			let loading = layui.loading;

			let cols = [[
                { type: 'checkbox' },
                { title: '词义', field: 'word' },
                { title: '作者', field: 'author', width: 150 },
                { title: '提交时间', field: 'lastDate', templet: '#user-createTime', width: 130 },
                { title: '操作', toolbar: '#user-bar', align: 'center', width: 130 }
            ]]

            table.render({
                elem: '#user-table',
                url: '/YuLiaoK/waitpage',
                page: true,
                cols: cols,
                skin: 'line',
                toolbar: '#user-toolbar',
                defaultToolbar: [{
                    title: '刷新',
                    layEvent: 'refresh',
                    icon: 'layui-icon-refresh',
                }, 'filter', 'print', 'exports'],
                request: {
                    pageName: 'PageIndex',
                    limitName: 'PageSize'
                },
                parseData: function (res) {
                    return {
                        "count": res.result.total,
                        'statusCode': res.code,
                        'data': res.result.items
                    };
                },
                response: {
                    statusName: 'statusCode',
                    statusCode: 200
                }
			});

            table.on('tool(user-table)', function (obj) {
                if (obj.event === 'view') {
                    layer.open({
                        title: ''
                        , content: '<img src="' + obj.data.gif + '" alt="' + obj.data.word + '">'
                    });
                }
			});
            table.on('toolbar(user-table)', function (obj) {
                if (obj.event === 'refresh') {
                    table.reload('user-table');
                } else if (obj.event === 'checkok') {
                    window.batchCheck(obj,1);
                } else if (obj.event === 'checknook') {
                    window.batchCheck(obj, -1);
                }
            });
            form.on('submit(user-query)', function (data) {
                table.reload('user-table', {
                    where: data.field
                })
                return false;
            });

			window.batchCheck = function (obj,state) {
				//
				var checkIds = common.checkField(obj, 'id');
				if (checkIds === "") {
					layer.msg("未选中数据", {icon: 3,time: 1000});
					return false;
				}               
                var postdata = { state: state,lstid:checkIds.split(',') }
                var msg = state>0 ? '确定要审核通过这些语料库吗' : '确定要丢弃这些语料库吗';
                layer.confirm(msg, {
					icon: 3,
					title: '提示'
				}, function (index) {
                    loading.Load(5, '请稍等...');					
                    http.ajax({
                        url: '/YuLiaoK/check',
                        data: JSON.stringify(postdata)
                    }).done(function (data) {
						toast.success({ title: "提示", message: "保存成功" });
                        layer.close(index);
						table.reload('user-table');
                    }).always(function () {
                        loading.loadRemove(500);
                    });
				});
			}
		})
	</script>
</body>
</html>
